import { ApiProperty } from '@nestjs/swagger';
import {
  Length,
  IsString,
  IsNotEmpty,
  IsOptional,
  IsNumber,
} from 'class-validator';
import { Role } from '../../roles/entities/role.entity';

export class CreateTeacherDto {
  @ApiProperty({ example: '1', description: 'id' })
  @IsOptional()
  tid?: number;

  @ApiProperty({ example: '1234567', description: '职工编号' })
  @IsString()
  @IsNotEmpty({ groups: ['create'], message: '职工编号必须填写' })
  t_code: string;

  @ApiProperty({ example: '张三', description: '姓名' })
  @IsString()
  @IsNotEmpty({ groups: ['create'], message: '姓名必须填写' })
  t_name: string;

  @ApiProperty({ example: '男', description: '性别' })
  @IsNumber()
  gender: number;

  @ApiProperty({ example: '123456', description: '密码' })
  @IsString()
  @IsOptional()
  // @IsNotEmpty({ groups: ['create'], message: '密码必须填写' })
  // @Length(6, 20, { groups: ['create'], message: '密码长度必须大于等于6位' })
  password: string;

  @ApiProperty({ example: '1', description: '手机号' })
  @IsOptional()
  t_tel?: number;

  @ApiProperty({ example: '角色名', description: '角色名' })
  @IsNumber(
    {
      allowNaN: false,
      allowInfinity: false,
    },
    { each: true },
  )
  @IsOptional()
  roleIds: number[];

  roles: Role[];
}
